<template>
  <div class="clas_All">
    <el-form class="const_top" :model="queryParams" size="small" :inline="true">
      <el-row>
        <el-col :span="24">
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="byMonth.relateId"
              placeholder="请选择部门"
              clearable
              @change="deptChange"
            >
              <el-option
                v-for="dict in deptOptions"
                :key="dict.relateId"
                :label="dict.label"
                :value="dict.relateId"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-date-picker
              clearable
              v-model="queryParams.createdTime"
              type="month"
              placeholder="选择月"
              @change="createdTimeChange"
              :disabled="mouday"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="queryParams.pandianCode"
              placeholder="1号至10号"
              clearable
              :disabled="mount"
            >
              <el-option
                v-for="dict in NewDropDownList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="getsta"
              >查询
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-col :span="24">
        <taber
          :columns="columns"
          :table-data="tableData"
          @row-click="handleRowClick"
          :show02="showOne"
          :params="queryParams"
        ></taber>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import taber from "@/components/ElTable/index";
import { getStageOperation } from "@/api/system/cost.js";
import { getPanDianCode, FindShopBom } from "@/api/system/stock";

export default {
  components: { taber },
  data() {
    return {
      queryParams: {},
      columns: [
        { label: "日期", prop: "" },
        { label: "营业额", prop: "sumAmount" },
        { label: "标准成本", prop: "sumStandardCost" },
        { label: "标准毛利率", prop: "standardProMarginStr" },
        { label: "实际成本", prop: "sumRealCost" },
        { label: "实际毛利率", prop: "realCostMarginStr" },
      ],
      tableData: [],
      showOne: true,
      deptOptions: [],
      client: null,

      deptOptions: [],
      DropDownList: [],
      NewDropDownList: [],
      byMonth: {},
      mouday: true,
      mount: true,
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    getsta() {
      if (this.byMonth.relateId) {
        this.queryParams.shopCode = this.byMonth.relateId;
      }
      // console.log(this.queryParams);
      getStageOperation(this.queryParams).then((res) => {
        if (res.code == 200) {
          if (res.data) {
            this.tableData.push(res.data);
            // console.log(this.tableData);
          }
        }
      });
    },
    handleQuery() {},
    handleRowClick() {},
    createdTimeChange(v) {
      let data = new Date(v);
      let y = data.getFullYear();
      let m = data.getMonth() + 1;
      this.byMonth.pandianData = y + String(m).padStart(2, "0");
      console.log(this.byMonth);
      getPanDianCode(this.byMonth).then((res) => {
        if (res.code == 200) {
          this.DropDownList = res.data;
          this.NewDropDownList = [];
          this.DropDownList.forEach((element) => {
            let label =
              new Date(element.startTime).getDate() +
              "号-" +
              new Date(element.endTime).getDate() +
              "号";
            this.NewDropDownList.push({
              value: element.pandianCode,
              label: label,
            });
          });
          if (res.data != []) {
            this.mount = false;
          }
        }
      });
    },
    deptChange(v) {
      // console.log(v);
      if (v) {
        this.mouday = false;
      } else {
        this.mouday = true;
      }
    },
  },
  created() {
    this.getsta();

    FindShopBom().then((res) => {
      // console.log(res);
      if (res.code == 200) {
        this.deptOptions = res.data;
      }
    });
  },
};
</script>

<style lang="scss" scoped>
.clas_All {
  margin: 20px;
}
</style>
